function Dog(name,energy){
  let _listeners={};
  this.energy=energy;
  this.name=name;

  let timer=setInerval(()=>{
    if(energy>0){
      emit('bark');
      this.energy--;
    }
    else{
      clearInterval(timer);
    }
  },1000);
  this.on=(evt,fn)=>{
    if(typeof(_listeners[evt]==='undefined')){
      _listeners[evt]=[];
    }
    _listeners[evt].push(fn);
  };
  function emit (evt,arg){
    if(typeof(_listeners[evt]==='undefined')){
      coonsole.error('Error :%s not defined!,evt');
      process.exit(1);
    }
    _listneners[evt].forEach((fn)=>{
      fn.call(this.arg);
    });
  }
} 
module.exports=Dog;
